{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Linear\n",
    "\n",
    "## 1.  scalar, vector, matrix , tensor_3....\n",
    "标量， 向量， 矩阵， 3阶张量，4阶 tensor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "tr_4 = np.array([\n",
    "    [[1, 2, 3,4],\n",
    "     [4, 5, 6,4],\n",
    "     [1, 2, 3,4]],\n",
    "\n",
    "    [[1, 2, 3,4],\n",
    "     [4, 5, 6,5],\n",
    "     [7, 8, 9,6]]\n",
    "    ])\n",
    "\n",
    "print(\"4 tensor \\n\",tr_4 )\n",
    "print(\"3 tensor \\n\",tr_4[1] )\n",
    "print(\"vector \\n\",tr_4[1][2] )\n",
    "print(\"scalar \\n\",tr_4[1][2][3] )\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Norm (范数)\n",
    "> To reprensent the size of a vector\n",
    "\n",
    "There are $L^2$ and $L^1$ norm.\n",
    "\n",
    "1. L1 norm\n",
    "\n",
    "$ ||\\vec{x}||_2 = \\sqrt{x^2_1 + x^2_2 + ... + x^2_n}\n",
    "                = \\sqrt{\\sum_{k=1}^n x^2_k}$\n",
    "\n",
    "2. L2 norm\n",
    "\n",
    "$ ||\\vec{x}||_1 = |x_1| + |x_2| + ... + |x_n|\n",
    "                = \\sum_{k=1}^n |x_k|$\n",
    "\n",
    "3. Conclude norm (prod)\n",
    "\n",
    "$ ||\\vec{x}||_p =( |x_1|^p + |x_2|^p + ... + |x_n|^p)^\\frac{1}{p}\n",
    "                = (\\sum_{k=1}^n |x_k|^p)\\frac{1}{p}$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 范数\n",
    "\n",
    "a = np.array([1,1,-1,-1])\n",
    "\n",
    "print(\"L2\\n\",np.linalg.norm(a))\n",
    "\n",
    "print(\"L1\\n\",np.linalg.norm(a,1))\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Matrix\n",
    "\n",
    "1. inverse matrix\n",
    "\n",
    "> determaint det 行列式\n",
    "If det's equal 0 , Then inverse matrix not exist\n",
    "\n",
    " $$ A = {a,b,c,d} $$\n",
    " $$ |A| = Det(A) = ab -cd$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.array([[1,2],[3,4]])\n",
    "print(np.linalg.det(a))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
